﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace MyMedia_App.Pages
{
    public partial class YouTubeDownloader_Tab : Form
    {
        MyMedia.YouTube yt = new MyMedia.YouTube();

        public YouTubeDownloader_Tab()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
            {
                Save2.Text = folderBrowserDialog1.SelectedPath;
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (URL.TextLength > 0)
            {
                if (yt.Create(URL.Text))
                {
                    yt.GetThumbnail();
                    VideoInfoBox.Text = yt.VideoTITLE;
                    VideoImage.Image = yt.Thumbnail;
                    VideoDescription.Text = yt.VideoDESC;

                    VideoInfoBox.Visible = true;
                    VideoImage.Visible = true;
                    VideoDescription.Visible = true;

                    groupBox2.Visible = true;

                    button3.Enabled = true;
                }
            }
            else
            {
                MessageBox.Show("YouTube link cannot be left blank!");
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            yt.DownloadComplete += new EventHandler(yt_DownloadComplete);
            yt.ProgressChange += new EventHandler(yt_ProgressChange);
            yt.DownloadVideo(yt.VideoURL, Save2.Text+"\\"+yt.VideoTITLE+".mp4");

            DLStatus.Visible = true;
            DLProgress.Visible = true;
            button2.Enabled = false;
            button3.Enabled = false;
            URL.Enabled = false;
        }

        private void yt_DownloadComplete(object sender, EventArgs e)
        {
            button2.Enabled = true;
            button3.Enabled = true;
            URL.Enabled = true;
            DLStatus.Text = "Download Complete";
            DLProgress.Value = 0;
        }
        private void yt_ProgressChange(object sender, EventArgs e)
        {
            DLStatus.Text = "Downloading: " + yt.VideoDownloadProgess.ToString() + "% Complete";
            DLProgress.Value = yt.VideoDownloadProgess;
        }

        private void YouTubeDownloader_Tab_Load(object sender, EventArgs e)
        {

        }
    }
}
